package com.heg.bk.dao.impl;

import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import com.heg.bk.dao.HibernateBaseDao;

/**
 * Hibernate常用方法封装(数据实现层)
 * @author 邓绪招
 * @time 2016-04-10
 * @version 1.1
 */
@Repository("hibernateBaseDaoImpl")
public class HibernateBaseDaoImpl extends HibernateDaoSupport implements HibernateBaseDao {
	
	private static final Log log = LogFactory.getLog(HibernateBaseDaoImpl.class);
	
	@Resource(name = "hibernateSessionFactory")
	public void setSuperSessionFactory(SessionFactory sessionFactory){
		super.setSessionFactory(sessionFactory);
	}

	public String saveObjectToRetId(Object transientInstance) {
		log.debug("saving " + transientInstance + " instance");
		String retObjId = "";
		try {
			retObjId = getHibernateTemplate().save(transientInstance).toString();
			log.debug("save successful");
			return retObjId;
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}
}
